﻿using es.tools.config;
using eslib.tools.config;
using System;
using static System.Console;

namespace demo
{
    class Program
    {
        static void Main(string[] args)
        {
            jsonTest();
            bsonTest();


            WriteLine("demo结束");
            ReadKey(true);
        }




        private static void bsonTest()
        {
            CustomConfig cfg = new()
            {
                value = 9394,
                str = "bson string section",
                flt = 6.28f,
            };

            //保存bson文件
            GenericBsonConfig.Save(cfg, "config.bson");

            //读取
            CustomConfig readcfg = GenericBsonConfig.Load<CustomConfig>("config.bson");
            WriteLine($"从bson读取:{readcfg}");
        }




        private static void jsonTest()
        {
            CustomConfig cfg = new()
            {
                value = 1314,
                str = "json test string",
                flt = 3.14f,
            };

            //保存json文件
            GenericJsonConfig.Save(cfg, "config.json");

            //读取
            CustomConfig readcfg = GenericJsonConfig.Load<CustomConfig>("config.json");
            WriteLine($"从json读取:{readcfg}");
        }
    }






    /// <summary>
    /// 自定义配置
    /// </summary>
    class CustomConfig
    {
        public int value { get; set; }

        public string str { get; set; }

        public float flt;

        public override string ToString()
        {
            return $"数值:{value} 字符串:{str} 浮点数:{flt}";
        }
    }

}
